module.exports = {
  publicPath: process.env.NODE_ENV === 'production' ? './' : '/',
  devServer: {
    port: 8081
  },
  css: {
    extract: false,  // 内联CSS，避免路径问题
    loaderOptions: {
      sass: {
        additionalData: `@import "@/styles/variables.scss";`
      }
    }
  },
  chainWebpack: config => {

    if (process.env.NODE_ENV === 'production') {
      // 修改HTML插件，替换资源路径
      config.plugin('html').tap(args => {
        args[0].templateParameters = {
          BASE_URL: './'
        }
        return args
      })
    }
  },
  pluginOptions: {
    electronBuilder: {
      nodeIntegration: true,
      contextIsolation: false,
      mainProcessFile: 'src/background.js',
      rendererProcessFile: 'src/main.js',
      builderOptions: {
        appId: 'com.linkverify.app',
        productName: 'LinkVerify',
        directories: {
          output: 'dist_electron'
        },
        asar: true,
        files: [
          "**/*",
          "!**/node_modules/*/{CHANGELOG.md,README.md,README,readme.md,readme}",
          "!**/node_modules/*/{test,__tests__,tests,powered-test,example,examples}",
          "!**/node_modules/*.d.ts",
          "!**/node_modules/.bin",
          "!**/*.{iml,o,hprof,orig,pyc,pyo,rbc,swp,csproj,sln,xproj}",
          "!.editorconfig",
          "!**/._*",
          "!**/{.DS_Store,.git,.hg,.svn,CVS,RCS,SCCS,.gitignore,.gitattributes}",
          "!**/{__pycache__,thumbs.db,.flowconfig,.idea,.vs,.nyc_output}",
          "!**/{appveyor.yml,.travis.yml,circle.yml}",
          "!**/{npm-debug.log,yarn.lock,.yarn-integrity,.yarn-metadata.json}"
        ],
        extraResources: [
          {
            from: "node_modules/merge-descriptors",
            to: "app/node_modules/merge-descriptors"
          }
        ],
        win: {
          target: 'nsis',
          icon: 'public/icon.ico',
          publisherName: 'GuLu'
        },
        mac: {
          target: 'dmg',
          icon: 'public/icon.icns'
        },
        linux: {
          target: 'AppImage',
          icon: 'public/icon.png'
        }
      }
    }
  },
  transpileDependencies: true
}